import pymysql


class DButil:
    conn = None

    @classmethod
    def __connect_db(cls):
        cls.conn = pymysql.connect(
            host="211.103.136.244",
            port=7061,
            user="student",
            password="iHRM_student_2022",
            database="ihrm",
            charset="utf8"
        )
        return cls.conn

    @classmethod
    def __close_db(cls):
        cls.conn.close()

    @classmethod
    def del_util(cls, sql):
        cursor = None
        result = None
        try:
            cls.conn = cls.__connect_db()
            cursor = cls.conn.cursor()
            cursor.execute(sql)
            result = cursor.fetchone()
            cls.conn.commit()
        except Exception as e:
            print("查询数据出错：", e)
        finally:
            cursor.close()
            cls.__close_db()
        return result